<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: kane <chengjin005@163.com> 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\wsapi\controller;

use app\wsapi\controller\BaseController;
use think\Db;

/**
 * Class 
 * @package app\admin\controller
 */
class ProjectController extends BaseController
{
	/**
	 * 团队
	 */
	public function tuandui()
	{
	
		//每页显示的条数
		$every_page = 5;
		//当前页码
		$p = $this->request->param('p');
		$p = isset($p)?$p:'1';
		//偏移量
		$start = ($p-1)*$every_page;

		//总共的页码
		$sum_count = Db::name('company')->count();
		$sum_page  = ceil($sum_count/$every_page);

		$result = Db::name('company')->order("id desc")->limit($start,$every_page)->select()->toArray();
		foreach($result as $k=>$v)
		{
			$param = json_decode($v['param'],true);
			$result[$k]['list'] = $param;
			unset($result[$k]['param']);
			$result[$k]['user_img'] = getServer().'effect/upload_xiaoguotu/'.$v['user_img'];
		}
		ajaxReturn(['status'=>1,'msg'=>'获取成功','data'=>$result,'sum_page'=>$sum_page,'p'=>$p]);
	}

	/**
	 * 新闻列表
	 */
	public function news()
	{
		//每页显示的条数
		$every_page = 5;
		//当前页码
		$p = $this->request->param('p');
		$p = isset($p)?$p:'1';
		//偏移量
		$start = ($p-1)*$every_page;

		//总共的页码
		$sum_count = Db::name('news')->count();
		$sum_page  = ceil($sum_count/$every_page);

		$result = Db::name('news')->order("id desc")->limit($start,$every_page)->select()->toArray();
		foreach($result as $k=>$v)
		{
			$result[$k]['img'] = getServer().'effect/upload_xiaoguotu/'.$v['img'];
		}


		ajaxReturn(['status'=>1,'msg'=>'获取成功','data'=>$result,'sum_page'=>$sum_page,'p'=>$p]);
	}

	/**
	 * 新闻详情
	 */
	public function newsDetail()
	{
		$id = $this->request->param('id');

		$result = Db::name('news')->where(['id'=>$id])->find();

		Db::name('news')->where(['id'=>$id])->update(['click_count'=>($result['click_count']+1)]);

		ajaxReturn(['status'=>1,'msg'=>'获取成功','data'=>$result]);
	}

	/**
	 * 招聘
	 * @return [type] [description]
	 */
	public function zhaopin()
	{
		//每页显示的条数
		$every_page = 5;
		//当前页码
		$p = $this->request->param('p');
		$p = isset($p)?$p:'1';
		//偏移量
		$start = ($p-1)*$every_page;

		//总共的页码
		$sum_count = Db::name('zhaopin')->count();
		$sum_page  = ceil($sum_count/$every_page);
		
		$result = Db::name('zhaopin')->order("id desc")->limit($start,$every_page)->select()->toArray();
		ajaxReturn(['status'=>1,'msg'=>'获取成功','data'=>$result,'sum_page'=>$sum_page,'p'=>$p]);
	}

	/**
	 * 招聘详情
	 */
	public function zhaopinDetail()
	{
		$id = $this->request->param('id');
		$result = Db::name('zhaopin')->where(['id'=>$id])->find();
		Db::name('zhaopin')->where(['id'=>$id])->update(['click_count'=>($result['click_count']+1)]);
		ajaxReturn(['status'=>1,'msg'=>'获取成功','data'=>$result]);
	}


	/**
	 * 留言
	 */
	public function liuyan()
	{
		$data = $this->request->param();
		$data['add_time'] = time();
		Db::name('liuyan')->insert($data);
	}
}